package pers.vic.base.web.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.springframework.web.util.WebUtils;


import pers.vic.base.bo.system.Principal;
import pers.vic.base.contant.BaseConsoleConstant;
import pers.vic.base.tools.ConsoleTools;
import pers.vic.base.tools.Tools;


/**
 * 保存请求的拦截器
 * @author VIC
 *
 */
public class SaveRequestInterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		if("GET".equalsIgnoreCase(request.getMethod())) {
			ConsoleTools.saveLastPageToSession(request);
			Principal principal = (Principal) WebUtils.getSessionAttribute(request, BaseConsoleConstant.USER_SESSION_KEY);
			if(principal != null ) {
				String currentUrl = Tools.getRequestUrl(request);//当前访问的url 
				principal.setLocation(currentUrl);//用户菜单选中状态
				principal.setPosition(currentUrl);//用于展示当前位置
			}
		}
		return true;
	}
	


}
